<template>
  <view class="page" :style="themeColor">
    <view class="flex benben-position-layout flex flex-wrap align-center emailChange_flex_0"
      :style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx'}">
      <view class='flex flex-wrap align-center justify-between flex-sub emailChange_fd0_0'>
        <view class='flex flex-wrap align-center' @tap.stop="handleJumpDiy" data-type="back" data-url="1">
          <text class='fu-iconfont2  emailChange_fd0_0_c0_c0'>&#xE794;</text>
        </view>
        <view class='flex flex-wrap align-stretch justify-center flex-sub'>
          <text class='emailChange_fd0_0_c1_c0'>修改邮箱</text>
        </view>
        <view class='flex flex-wrap align-center emailChange_fd0_0_c2'>
        </view>
      </view>

    </view>
    <view :style="{height: (88+StatusBarRpx)+'rpx'}"></view>
    <!---验证码flex布局开始-->
    <view class="flex flex-direction align-center benben-flex-layout emailChange_flex_1">
      <text class='emailChange_fd1_0'>我们要对您绑定的邮箱进行验证：</text>
      <text class='emailChange_fd1_1'>{{email}}</text>
    </view>

    <!---验证码flex布局结束-->
    <benben-digital-password v-model='code' :box-num='6' mode='number'
      class-name='flex flex align-center justify-center emailChange_flex_password_2'>
      <template #default="{ content, active, index }">
        <view :key="index" v-if="active"
          class="flex align-center justify-center active-digital-password emailChange_flex_password_active_2">
          {{ content }}
        </view>
        <view :key="index" v-else class="flex align-center justify-center emailChange_flex_password_active_2">
          {{ content }}
        </view>
      </template>
    </benben-digital-password>
    <!---flex布局flex布局开始-->
    <view class="flex flex-direction flex-wrap align-stretch justify-center benben-flex-layout">
      <view class='flex flex-wrap align-center justify-center'>
        <text class='flex  emailChange_fd3_0_c0' @tap.stop="getemailcode" v-if="xianshi==1">获取验证码</text>
        <text class='flex  emailChange_fd3_0_c0' v-else>{{countDown}}s后重新获取</text>
      </view>
      <button class='emailChange_fd3_1' @tap.stop="changeBingDingPhoneFunc()">下一步</button>
    </view>

    <!---flex布局flex布局结束-->


  </view>
</template>
<script>
  import {
    validate
  } from '@/common/utils/validate.js'
  export default {
    components: {},


    data() {
      return {
        "phone": "",
        "code": "",
        email: '',
        list: '',
        type: 7,
        xianshi: 1,
        countDown: 60, // 初始倒计时60秒
        timer: null // 定时器
      };
    },
    computed: {
      themeColor() {
        return this.$store.getters.themeColor
      },

    },
    watch: {},
    onLoad(options) {
      this.getuser()
    },
    onUnload() {

    },
    onReady() {

    },
    onShow() {

    },
    onHide() {

    },
    onResize() {

    },
    onPullDownRefresh() {

    },
    onReachBottom(e) {

    },
    onPageScroll(e) {

    },
    methods: {
      async getuser() {
      	let id1 = uni.getStorageSync("USER_INFO")
      	this.userid = id1.id
      	console.log(this.userid, 'userid')
      	let res = await this.$api.post(global.apiUrls.userinfo, {
      		user_id: this.userid,
      	});
      	if (res.data.code != 1) {
      		this.$message.info(res.data.msg)
      		return
      	}
      	this.email = res.data.data.email
      },
      //获取邮箱验证码
      async getemailcode() {
        let res = await this.$api.post(global.apiUrls.a6473344de61d8, {
          email: this.email,
          is_test: 1,
          type: this.type
        })
        if (res.data.code != 1) {
          this.$message.info(res.data.msg)
          return
        }
        this.$message.info(res.data.data.code)
        console.log(res.data.data.code, 'res.data.data.code')
        this.startCountDown()
      },
      startCountDown() {
        this.xianshi = 2
        this.timer = setInterval(() => {
          if (this.countDown > 0) {
            this.countDown--
          } else {
            clearInterval(this.timer)
            location.reload()
            this.xianshi = 1
          }
        }, 1000)
      },
      //修改绑定手机号
      async changeBingDingPhoneFunc() {
        if (!validate(this.code, 'require')) {
          this.$message.info('验证码不能为空');
          return false;
        }
        let res = await this.$api.post(global.apiUrls.a643673025ef00, {
          email: this.email,
          code: this.code,
          type: this.type,
          area_code: this.list,
          phone: this.phone,
        })
        if (res.data.code != 1) {
          this.$message.info(res.data.msg)
          return
        }
        this.$message.info(res.data.msg)
        this.$urouter.redirectTo(`/pages/xtsz/bindingEmail/bindingEmail?email=${this.email}`);
      }
    }
  };
</script>
<style lang="scss" scoped>
  .page {
    width: 100vw;
    overflow-x: hidden;
    min-height: calc(100vh - var(--window-bottom));
    background: #fff;
    background-size: 100% auto !important;
  }

  .emailChange_flex_0 {
    border-bottom: 1px solid #eee;
    background: #fff;
    width: 750rpx;
    height: 88rpx;
    overflow: hidden;
    z-index: 10;
    top: 0rpx;
    background-size: 100% auto !important;
  }

  .emailChange_fd0_0_c2 {
    width: 32rpx;
    height: 32rpx;
  }

  .emailChange_fd0_0_c1_c0 {
    font-size: 36rpx;
    font-weight: 500;
    color: #333;
    line-height: 88rpx;
  }

  .emailChange_fd0_0_c0_c0 {
    font-size: 32rpx;
    font-weight: 500;
    color: #333;
    line-height: 88rpx;
  }

  .emailChange_fd0_0 {
    margin: 0rpx 32rpx 0rpx 32rpx;
  }

  .emailChange_flex_1 {
    padding: 103rpx 0rpx 0rpx 0rpx;
  }

  .emailChange_fd1_1 {
    margin: 51rpx 0rpx 71rpx 0rpx;
    line-height: 37rpx;
    font-size: 28rpx;
    font-weight: 400;
    color: #484848;
  }

  .emailChange_fd1_0 {
    font-size: 28rpx;
    font-weight: 400;
    color: #333333;
  }

  .emailChange_flex_password_active_2 {
    border: 1px solid var(--benbenbdColor0);
    width: 100rpx;
    height: 100rpx;
  }

  ::v-deep .emailChange_flex_password_2 {
    margin: 24rpx 0rpx 24rpx 0rpx;
  }

  .emailChange_fd3_1 {
    background: var(--benbenbgColor2);
    border-radius: 44rpx 44rpx 44rpx 44rpx;
    font-size: 32rpx;
    color: #fff;
    margin: 80rpx 32rpx 0rpx 32rpx;
    height: 88rpx;
    line-height: 88rpx;
    width: 686rpx;
  }

  .emailChange_fd3_0_c0 {
    font-size: 28rpx;
    font-weight: 400;
    color: var(--benbenFontColor4);
    text-align: center;
  }
</style>
